package service;

import model.User;
import dao.UserDao;
import dao.UserDaoImpl;
import service.UserService;

import java.sql.SQLException;
import java.util.ArrayList;

public class UserServiceImpl implements UserService {
    UserDao userDao = new UserDaoImpl();

    @Override
    public User getUserByID(int id) throws SQLException {
        return userDao.getUserByID(id);
    }

    @Override
    public User getUserByName(String username) throws SQLException {
        return userDao.getUserByName(username);
    }

    @Override
    public ArrayList<User> getAllUser(int pageIndex, int pageSize) throws SQLException {
        return userDao.getAllUser(pageIndex, pageSize);
    }

    @Override
    public int getUserCount() throws SQLException {
        return userDao.getUserCount();
    }


    @Override
    public boolean doUpdate(User user) {
        return userDao.updateUser(user) == 1;
    }

    @Override
    public boolean doDelete(int id) {
        return userDao.deleteUser(id) == 1;
    }

    @Override
    public boolean addUser(User user) {
        return userDao.addUser(user) == 1;
    }

    @Override
    public ArrayList<User> searchUser(String keyword, int pageIndex, int pageSize) throws SQLException {
        return userDao.searchUser(keyword, pageIndex, pageSize);
    }

    @Override
    public int countSearchUser(String keyword) throws SQLException {
        return userDao.countSearchUser(keyword);
    }
}



